package com.scenic.rd_android.servicetest;

import android.app.Service;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class RemoteService extends Service {
    public RemoteService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        return new MMM();
    }


    class MMM extends IMyAidlInterface.Stub {

        @Override
        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

        }

        @Override
        public String execute(int i) throws RemoteException {
            File file = new File(Environment.getExternalStorageDirectory(),"ddd.txt");
            FileOutputStream fi = null;
            try {
                fi = new FileOutputStream(file);
                FileChannel fc = fi.getChannel();
                fc.lock();
                fi.write("execute".getBytes());
                fi.flush();
                fi.close();
                Log.w("RemoteService", "wirte file");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return e.getMessage();
            } catch (IOException e) {
                e.printStackTrace();
                return e.getMessage();
            }

            return "on";
        }
    }
}
